package org.ala.tiktools.rpc.tcp.client_server;

import java.util.concurrent.CompletableFuture;
import java.util.function.Consumer;

import org.ala.tiktools.rpc.netty.handler.RpcChannelInitializer;
import org.ala.tiktools.rpc.plugin.node.AbstractNode;
import org.ala.tiktools.rpc.plugin.node.NodeKey;

import io.netty.channel.Channel;

/**
 * tcp协议实现的节点信息
 *
 * @author ala
 * @date 2025-04-08 08:56
 */
public class TcpNode extends AbstractNode {


    /**
     *  持有的Channel
     */
    protected Channel channel;

    @Override
	protected String type() {
		return "tcp";
	}

	public TcpNode(String group, NodeKey nodeKey) {
        super(group, nodeKey);
    }

    @Override
    protected CompletableFuture<Channel> connect(Consumer<Channel> registered, Consumer<Channel> unRegistered) {
        return TcpNettyTools.connect(key().getHost(), key().getPort(), new RpcChannelInitializer(null, true, false, registered, unRegistered));
    }

}
